# Contributor: David Huffman <storedbox@outlook.com>
# Maintainer: David Huffman <storedbox@outlook.com>
pkgname=libtbb
pkgver=2020.2
pkgrel=0
pkgdesc="Intel® TBB, a widely used C++ template library for task parallelism"
url="https://github.com/oneapi-src/oneTBB"
arch="all"
license="GPL-2.0-only"
makedepends="linux-headers cmake"
subpackages="$pkgname-dev"
source="tbb-$pkgver.tar.gz::https://github.com/oneapi-src/oneTBB/archive/v$pkgver.tar.gz
	musl.patch
	tbb.pc
	tbbmalloc.pc
	tbbmalloc_proxy.pc
	"
builddir="$srcdir/oneTBB-$pkgver"

prepare() {
	default_prepare

	sed -i 's|CPLUS = g..|CPLUS = $(CXX)|g' build/linux.gcc.inc
	sed -i 's|CONLY = gcc|CONLY = $(CC)|g' build/linux.gcc.inc

	sed -e "s@#define MALLOC_UNIXLIKE_OVERLOAD_ENABLED __linux__@@"  \
		-i src/tbbmalloc/proxy.h

	sed -i "s|@@VERSION@@|$pkgver|" -i "$srcdir"/*.pc
}

build() {
	make
}

package() {
	mkdir -p "$pkgdir"/usr/lib
	mkdir -p "$pkgdir"/usr/include

	mv build/linux_*/*.so* "$pkgdir"/usr/lib
	mv include/tbb "$pkgdir"/usr/include

	cmake \
		-DINSTALL_DIR="$pkgdir"/usr/lib/cmake/TBB \
		-DSYSTEM_NAME=Linux \
		-DLIB_REL_PATH=../.. \
		-DINC_REL_PATH=../../../include \
		-P cmake/tbb_config_installer.cmake

	install -Dm0644 "$srcdir"/*.pc -t "$pkgdir"/usr/lib/pkgconfig
}

sha512sums="b9a5d0e814ebd2e69690585bcfb5a545c06f030e193154bef161ac59066044109f8a0305a9ba535c447739da3380c351067db19c38de4bf96ec742b044f39885  tbb-2020.2.tar.gz
c5f2d284e63fa3e9a835df45692355946fa3cd2f31ffb775ef8eff18780d28203115e799d70d547526c3a5c2b2290cb032e1eaa6160e188598abe62d89d2480e  musl.patch
b7849e84c5f4d868ad19dc4a2433492facd1f75fe6e5cb0afc334e8f07bb4657d318ee1bc53f7890bfb8a87c7233bba85b61aba2aec9ea3dc24652a4bdec4dde  tbb.pc
25b0bfe2067f287064f81dc434ac70336ad42fdd7fa91cded2e467f3939000480e1012675dc4e435a1712cf9b968cb565f213dfffb3f69ad46929aec237b9a02  tbbmalloc.pc
5952862755736fb85982281b3953183ed9d4657497a7f6bae1ef66bd1e2265882773764f07e46679b2aa750f80f47cc2a019024822ab5fa272b718c539ef3462  tbbmalloc_proxy.pc"
